package cn.dengta.webapp.trade.entity.meta;

import cn.dengta.webapp.trade.entity.meta.MetaConfig.MetaRuleConfig;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.Assert;

/**
 * 缘分雷达规则配置
 */
@Getter
@Setter
public class FateRadarRule implements MetaRuleConfig {

	/** 付费钻石 */
	protected int coin;
	/** 首次免费次数 */
	protected int firstFreeTimes;
	/** 每日免费次数 */
	protected int freeTimes;

	@Override
	public void validate() {
		Assert.isTrue(coin >= 0, "付费钻石不能小于0！");
		Assert.isTrue(firstFreeTimes >= 0, "首次免费次数不能小于0！");
		Assert.isTrue(freeTimes >= 0, "每日免费次数不能小于0！");
	}

	@Override
	public void init(MetaRuleConfig config) {
		FateRadarRule cfg = (FateRadarRule) config;
		this.coin = cfg.coin;
		this.firstFreeTimes = cfg.firstFreeTimes;
		this.freeTimes = cfg.freeTimes;
	}

	public int freeTimes(boolean isFirst) {
		return isFirst ? firstFreeTimes : freeTimes;
	}

}
